<template>
	<view class="content">
		<!-- <nav-header /> -->
		<view class="tab-card flex-row-start" :style="{top: `${getTop()}`}">
			<view class="tab-item" :class="{'tab-item-active': tabId == 1}" @click="setTabId(1)">待盘点</view>
			<view class="tab-item" :class="{'tab-item-active': tabId == 2}" @click="setTabId(2)">已盘点</view>
		</view>
		<view class="list-card-wrap" style="margin-top: 96rpx;">
			<view v-for="(item,index) in tableData" v-if="tableData.length" :key="index" class="list-card" @click="toPage(item)">
				<view class="flex-row-between">
					<view class="flex-row" @click.stop="toDetail(item)">
						<text class="gray-text">盘点任务编号</text>
						<text class="black-text-34" style="margin-left: 20rpx;">{{item.checkNo}}</text>
						<uni-icons type="right" size="16" color="#8997A8"></uni-icons>
					</view>
					<!-- <view class="tag">{{getDict(item.checkWay, checkWayList)}}</view> -->
				</view>
				<view class="content flex-column-center-start" style="padding: 16rpx 25rpx; line-height: 1.5;">
					<view class="flex-row flex1">
						<text class="gray-text">位  置：  </text>
						<text class="black-text">{{item.locationNo}}</text>
					</view>
					<view class="flex-row flex1">
						<text class="gray-text">货  架：  </text>
						<text class="black-text">{{item.containerNo}}</text>
					</view>
					<view class="flex-row flex1">
						<text class="gray-text">托  盘：  </text>
						<text class="black-text">{{item.trayNo}}</text>
					</view>
					<view class="flex-row flex1">
						<text class="gray-text">物  料：  </text>
						<text class="black-text">{{item.productName}}</text>
					</view>
				</view>
				<view class="flex-row-between" v-if="tabId == 1">
					<text class="gray-text"></text>
					<view class="flex-row">
						<navigator :url="'/pages/in/stockCheck/list?checkDetailNo='+item.checkDetailNo+'&locationNo='+item.locationNo+'&containerNo='+item.containerNo+'&trayNo='+item.trayNo+'&productNo='+item.productNo+'&batchNo='+item.batchNo" hover-class="other-navigator-hover">
							<view class="botton p-botton">盘点</view>
						</navigator>
					</view>
				</view>
			</view>
			
		</view>
		<view class="no-table-data"><text>暂无更多数据</text></view>
	</view>
</template>

<script>
	import { getDict, getTop } from "@/utils/common"
	import {
		getStockCheckList,
		
		queryCheckTaskDetails,
		queryCheckTaskCompletedDetails,
		queryCheckDetailInfos,
		checkComplete
	} from "./api"
	
	export default {
		data() {
			return {
				// 遮罩层
				loading: true,
				// 查询参数
				queryParams: {
		
				},
				searchValue: '',
				tabId: 1,
				tableData: [],
				checkWayList:[],
				getDict,
				getTop
			}
		},
		onNavigationBarSearchInputChanged(obj){
			if(!obj.text){
				this.queryParams.no = '';
				this.refreshList()
			}
		},
		onNavigationBarSearchInputConfirmed(obj) {
			// obj.text
			this.queryParams.no = obj.text;
			this.refreshList()
		},
		// 上拉加载
		onReachBottom() {
			if (this.tableData.length == this.total) {
				return;
			}
			this.queryParams.pageNum++;
			this.getList();
		},
		onLoad(option) {
			let that = this
			uni.$on('refreshList1',function(data){
				that.refreshList()
			})
			uni.$on('refreshList2',function(data){
				that.tabId = 2
				that.refreshList()
			})
			// 获取盘点方式字典
			// this.getDicts("storehouse_check_way").then(res => {
			//     this.checkWayList = res.data;
			// });
			this.getList()
		},
		onUnload(){
			uni.$off('refreshList1')
		},
		methods: {
			toPage(item) {
				if (this.tabId == 2) {
					this.toDetail(item)
				}
			},
			toDetail(item){
				this.$tab.navigateTo("/pages/in/stockCheck/list?checkDetailNo='"+item.checkDetailNo+'&locationNo='+item.locationNo+'&containerNo='+item.containerNo+'&trayNo='+item.trayNo+'&productNo='+item.productNo+'&batchNo='+item.batchNo);
			},
			setTabId(tabId) {
				this.tabId = tabId;
				this.refreshList();
			},
			refreshList(){
				this.tableData = [];
				// this.total = 0;
				// this.queryParams.pageNum = 1;
				this.getList();
			},
			getList() {
				uni.showLoading({
					title: '加载中...'
				});
				
				let api = null
				if(this.tabId == 2){
					api = queryCheckTaskCompletedDetails
				}else{
					api = queryCheckTaskDetails 
				}
				api(this.queryParams).then(res => {
					if (res.code == 200) {
						this.tableData = res.data;
					}
					uni.hideLoading();
				});
			},
			complete(item){
				if(item.actualQty && item.actualQty!=0){
					// [${item.no}]
					this.$modal.confirm(`是否确认完成任务`).then(() => {
						complete(item).then(res=>{
							this.refreshList()
							this.$modal.msgSuccess("操作成功");
						})
					})
				}else{
					// [${item.no}]
					this.$modal.msg(`任务单实际入库数量不能为0`);
					return
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F8F8F8;
	}
</style>
<style lang="scss" scoped>
	.content {
		// margin: 17rpx 25rpx;
	}
</style>
